package com.hig.ledger.service.impl;

import java.util.List;

import com.ruoyi.common.annotation.DataScope;
import com.ruoyi.common.core.domain.model.LoginUser;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.ServletUtils;
import com.ruoyi.framework.web.service.TokenService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.hig.ledger.mapper.LedgerConfinedSpaceMapper;
import com.hig.ledger.domain.LedgerConfinedSpace;
import com.hig.ledger.service.ILedgerConfinedSpaceService;

/**
 * 受限空间台账Service业务层处理
 * 
 * @author scp
 * @date 2024-09-20
 */
@Service
public class LedgerConfinedSpaceServiceImpl implements ILedgerConfinedSpaceService 
{
    @Autowired
    private LedgerConfinedSpaceMapper ledgerConfinedSpaceMapper;
    @Autowired
    private TokenService tokenService;

    /**
     * 查询受限空间台账
     * 
     * @param id 受限空间台账ID
     * @return 受限空间台账
     */
    @Override
    public LedgerConfinedSpace selectLedgerConfinedSpaceById(Long id)
    {
        return ledgerConfinedSpaceMapper.selectLedgerConfinedSpaceById(id);
    }

    /**
     * 查询受限空间台账列表
     * 
     * @param ledgerConfinedSpace 受限空间台账
     * @return 受限空间台账
     */
    @Override
    @DataScope(deptAlias = "d")
    public List<LedgerConfinedSpace> selectLedgerConfinedSpaceList(LedgerConfinedSpace ledgerConfinedSpace)
    {
        return ledgerConfinedSpaceMapper.selectLedgerConfinedSpaceList(ledgerConfinedSpace);
    }

    /**
     * 新增受限空间台账
     * 
     * @param ledgerConfinedSpace 受限空间台账
     * @return 结果
     */
    @Override
    public int insertLedgerConfinedSpace(LedgerConfinedSpace ledgerConfinedSpace)
    {
        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        ledgerConfinedSpace.setCreateBy(loginUser.getUser().getUserName());
        ledgerConfinedSpace.setDeptId(loginUser.getUser().getDeptId());
        ledgerConfinedSpace.setCreateTime(DateUtils.getNowDate());
//        long id = ledgerConfinedSpaceMapper.getNextId();
//        ledgerConfinedSpace.setId(id);
        return ledgerConfinedSpaceMapper.insertLedgerConfinedSpace(ledgerConfinedSpace);
    }

    /**
     * 修改受限空间台账
     * 
     * @param ledgerConfinedSpace 受限空间台账
     * @return 结果
     */
    @Override
    public int updateLedgerConfinedSpace(LedgerConfinedSpace ledgerConfinedSpace)
    {
        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        ledgerConfinedSpace.setUpdateBy(loginUser.getUser().getUserName());
        ledgerConfinedSpace.setUpdateTime(DateUtils.getNowDate());
        return ledgerConfinedSpaceMapper.updateLedgerConfinedSpace(ledgerConfinedSpace);
    }

    /**
     * 批量删除受限空间台账
     * 
     * @param ids 需要删除的受限空间台账ID
     * @return 结果
     */
    @Override
    public int deleteLedgerConfinedSpaceByIds(Long[] ids)
    {
        return ledgerConfinedSpaceMapper.deleteLedgerConfinedSpaceByIds(ids);
    }

    /**
     * 删除受限空间台账信息
     * 
     * @param id 受限空间台账ID
     * @return 结果
     */
    @Override
    public int deleteLedgerConfinedSpaceById(Long id)
    {
        return ledgerConfinedSpaceMapper.deleteLedgerConfinedSpaceById(id);
    }
}
